﻿bob.ns.setNs('bob.string.tests', {

    TestString: function () {

        this.test_formatString = function () {

            bob.assert.throwsError(function () {
                bob.string.formatString(null, 1);
            }, '1');

            var format1 = 'Hello from format #1.';
            bob.assert.equals(format1, bob.string.formatString(format1, 2));

            var format2 = 'Hello from format #{0}.';
            bob.assert.equals('Hello from format #2.', bob.string.formatString(format2, 2));
            bob.assert.notEquals('Hello from format #2.', bob.string.formatString(format2, 1));

            var format3 = '{0}+{1}={2}';
            bob.assert.equals('0+1=1', bob.string.formatString(format3, 0, 1, 1));
            bob.assert.equals('1+1=2', bob.string.formatString(format3, 1, 1, 2));
            bob.assert.equals('Tengiz+Tutisani=TengizTutisani', bob.string.formatString(format3, 'Tengiz', 'Tutisani', 'TengizTutisani'));

        };

        this.test_formatTemplate = function () {

            bob.assert.throwsError(function () {
                bob.string.formatTemplate(null, 1);
            }, '1');

            bob.assert.throwsError(function () {
                bob.string.formatTemplate('what is {missing} here?', { });
            }, '1.1');

            var format0 = 'what is {missing} here?';
            bob.assert.equals('what is  here?', bob.string.formatTemplate(format0, { }, true));

            var format1 = 'Hello from format #1.';
            bob.assert.equals(format1, bob.string.formatTemplate(format1, { whatever: 2 }));

            var format2 = 'Hello from format #{two}.';
            bob.assert.equals('Hello from format #2.', bob.string.formatTemplate(format2, { two: 2 }));
            bob.assert.notEquals('Hello from format #2.', bob.string.formatTemplate(format2, { two: 1 }));

            var format3 = '{first}+{second}={third}';
            bob.assert.equals('0+1=1', bob.string.formatTemplate(format3, { first: 0, second: 1, third: 1 }));
            bob.assert.equals('1+1=2', bob.string.formatTemplate(format3, { first: 1, second: 1, third: 2 }));
            bob.assert.equals('Tengiz+Tutisani=TengizTutisani', bob.string.formatTemplate(format3, { first: 'Tengiz', second: 'Tutisani', third: 'TengizTutisani' }));

        };
    }

});

